package icu.wdtt.service.Impl;

import icu.wdtt.mapper.AuthorityMapper;
import icu.wdtt.model.Authority;
import icu.wdtt.service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.Min;
import java.util.List;
@Service
public class AuthorityServiceImpl implements AuthorityService {
    @Autowired
    private AuthorityMapper authorityMapper;
    @Override
    public Authority get(@Min(0) int aid) {
        Authority authority = authorityMapper.get(aid);
        if(authority != null){
            return  authority;
        }
        return null;
    }

    @Override
    public List<Authority> getAll() {
        return authorityMapper.getAll();
    }

    @Override
    public Boolean add(Authority authority) {
        try {
            authorityMapper.add(authority);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public Boolean del(int aid) {
        try {
            authorityMapper.del(aid);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public Boolean update(Authority authority) {
        try {
            authorityMapper.update(authority);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
